/* GUI CONVERTED from reoptr11.p (converter v1.76) Sun Aug 25 20:59:44 2002 */
/* reoptr11.p - LABOR REJECT TRANSACTION BY PART (REPETITIVE)           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.3.4 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 5.0      LAST MODIFIED: 05/19/89   BY: emb      */
/* REVISION: 5.0      LAST MODIFIED: 10/17/90   BY: emb  *B801*/
/* REVISION: 6.0      LAST MODIFIED: 09/25/90   BY: SMM  *D072*/
/* REVISION: 6.0      LAST MODIFIED: 10/17/90   BY: SMM  *D104*/
/* REVISION: 6.0      LAST MODIFIED: 11/20/90   BY: emb  *D223*/
/* REVISION: 6.0      LAST MODIFIED: 03/22/91   BY: emb  *D448*/
/* REVISION: 6.0      LAST MODIFIED: 07/22/91   BY: bjb  *D782*/
/* REVISION: 6.0      LAST MODIFIED: 08/12/91   BY: pma  *D806*/
/* REVISION: 7.0      LAST MODIFIED: 10/08/91   BY: pma  *F003**/
/* REVISION: 7.0      LAST MODIFIED: 03/09/92   BY: smm  *F230*/
/* REVISION: 7.0      LAST MODIFIED: 03/23/92   BY: pma  *F089*/
/* REVISION: 7.0      LAST MODIFIED: 03/30/92   BY: emb *F331*/
/* REVISION: 7.0      LAST MODIFIED: 06/17/92   BY: emb *F662*/
/* REVISION: 7.0      LAST MODIFIED: 06/26/92   BY: emb *F705*/
/* REVISION: 7.3      LAST MODIFIED: 10/13/92   BY: emb *G184*/
/* REVISION: 7.3      LAST MODIFIED: 11/25/92   BY: emb *G357*/
/* REVISION: 7.3      LAST MODIFIED: 02/24/93   BY: emb *G760*/
/* REVISION: 7.4      LAST MODIFIED: 07/22/93   BY: pcd *H039* */
/* REVISION: 7.4      LAST MODIFIED: 01/12/94   BY: qzl *H276*/
/* Oracle changes (share-locks)    09/12/94           BY: rwl *FR25*    */
/* REVISION: 8.5      LAST MODIFIED: 10/24/94   BY: mwd *J034*          */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN76*          */
/* REVISION: 7.3      LAST MODIFIED: 11/10/94   BY: ljm *GO05*          */
/* REVISION: 7.4      LAST MODIFIED: 12/29/94   BY: cpp *FT95*          */
/* REVISION: 7.3      LAST MODIFIED: 02/28/95   BY: qzl *F0H9*/
/* REVISION: 7.3      LAST MODIFIED: 05/11/95   BY: ais *G0MM*/
/* REVISION: 7.3      LAST MODIFIED: 11/01/95   BY: ais *G0V9*/
/* REVISION: 8.5      LAST MODIFIED: 04/09/96   BY: jym *G1Q9*/
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*/
/* REVISION: 8.5      LAST MODIFIED: 05/31/96   BY: lal *J0PN*/
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: ejh *K001*         */
/* REVISION: 8.6      LAST MODIFIED: 12/26/96 BY: *H0Q8* Julie Milligan*/

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane    */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.9.3.3    BY: Jean Miller          DATE: 04/26/02  ECO: *P06H*  */
/* $Revision: 1.9.3.4 $         BY: Vivek Gogte          DATE: 08/06/02  ECO: *N1QQ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE          */
{mfdtitle.i "2+ "}

{gldydef.i new}
{gldynrm.i new}
define new global shared variable global_rsntyp as character.

define new shared variable gldetail     like mfc_logical no-undo initial no.
define new shared variable gltrans      like mfc_logical no-undo initial no.
define new shared variable wr_recno     as recid.
define new shared variable wc_recno     as recid.
define new shared variable op_recno     as recid.
define new shared variable comp         like ps_comp.
define new shared variable eff_date     as date.
define new shared variable wo_recid     as recid.
define new shared variable wo_recno     as recid.
define new shared variable ophist_recid as recid.
define new shared variable pay_rate     like emp_pay_rate.
define new shared variable last_date    like op_date.
define new shared variable conv         like um_conv label "Conv".
define new shared variable part         like op_part no-undo.
define new shared variable op           like ps_op no-undo.
define new shared variable bom_code     as character format "x(18)"
                                        label "BOM".
define new shared variable routing      as character format "x(18)"
                                        label "Routing".
define new shared variable mod_issrc    like mfc_logical
                                        label "Modify Backflush".
define new shared variable schedule_id  like wo_lot.
define new shared variable site         like rps_site no-undo.
define new shared variable prline       like rps_line no-undo.
define new shared variable undo-all     like mfc_logical no-undo.

define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i} /*CONSTANTS DEFINITIONS*/

define new shared frame a.
define variable um         like pt_um.
define variable disp_units as character format "x(15)".
define variable rsn_desc1  like rsn_desc.

if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.

/* DEFINE VARIABLES FOR BILL OF MATERIAL EXPLOSION */
{gpxpld01.i "new shared"}

{gpglefv.i}

/* Input frame definition */
{reopf11a.i}

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.

if available mfc_ctrl and mfc_logical = true then do:
   {pxmsg.i &MSGNUM=5122 &ERRORLEVEL=3}
   message.
   message.
   undo, leave.
end.

assign
   last_date = today
   site = global_site.
find si_mstr no-lock where si_site = site no-error.
display
   site si_desc when (available si_mstr)
   last_date
with frame a1.

/* DISPLAY */
view frame a1.
view frame a.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   do with frame a1:
      ststatus = stline[1].
      status input ststatus.

      prompt-for
         site
         last_date
      with frame a1
      editing:
         if frame-field = "site" then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp.i si_mstr site si_site site si_site si_site}
            if recno <> ? then do:
               display si_site @ site si_desc.
            end.
         end.
         else do:
            readkey.
            apply lastkey.
         end.
      end.

      assign
         site
         last_date
         eff_date = last_date.

      find si_mstr
      no-lock
         where si_site = site no-error.
      if not available si_mstr then do:
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3} /* Site code does not exist*/
         next-prompt site.
         undo, retry.
      end.

      {gprun.i ""gpsiver.p""
         "(input site, input recid(si_mstr), output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0 then do:
         /*USER DOES NOT HAVE ACCESS TO THIS SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         next-prompt site.
         undo, retry.
      end.

      display si_desc with frame a1.
      global_site = si_site.

      /* Check effective date */

      {gpglef1.i
         &module = ""WO""
         &entity = si_entity
         &date = last_date
         &prompt = "last_date"
         &frame = "a1"
         &loop = "mainloop"
         }

      ststatus = stline[1].
      status input ststatus.

      loop-rpt:
      repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

         prompt-for
            op_part
            op_wo_op
            prline
         with frame a
         editing:
            if frame-field = "op_part" then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp.i pt_mstr op_part pt_part op_part pt_part pt_part}

               if recno <> ? then do:
                  find ptp_det no-lock where ptp_part = pt_part
                     and ptp_site = input site no-error.

                  if available ptp_det then do:
                     if ptp_routing > ""
                     then
                        routing = ptp_routing.
                     else
                        routing = "".
                     if ptp_bom_code > ""
                     then
                        bom_code = ptp_bom_code.
                     else
                        bom_code = "".
                  end.
                  else do:
                     if pt_routing > ""
                     then
                        routing = pt_routing.
                     else
                        routing = "".
                     if pt_bom_code > ""
                     then
                        bom_code = pt_bom_code.
                     else
                        bom_code = "".
                  end.

                  display pt_part @ op_part pt_desc1.

                  find first ro_det no-lock where ro_routing =
                     if routing > "" then routing else pt_part no-error.
                  if available ro_det
                  then
                     display ro_op @ op_wo_op ro_desc.
                  else
                     display "" @ op_wo_op "" @ ro_desc.

                  display "" @ prline "" @ ln_desc.
                  for each lnd_det no-lock where
                        lnd_site = site and lnd_part = pt_part
                        and (lnd_start <= input last_date or lnd_start = ?)
                     with frame a:
                     find ln_mstr no-lock where ln_line = lnd_line
                        and ln_site = lnd_site no-error.
                     if available ln_mstr
                     then
                        display ln_line @ prline ln_desc.
                     else
                        display "" @ prline "" @ ln_desc.
                     leave.
                  end.
                  display routing bom_code with frame a.
               end.
               recno = ?.
            end.
            else
            if frame-field = "op_wo_op"
               and can-find (pt_mstr where pt_part = input op_part)
            then do:

               find pt_mstr no-lock where
                  pt_part = input op_part no-error.
               find ptp_det no-lock where ptp_part = pt_part
                  and ptp_site = input site no-error.

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp01.i ro_det op_wo_op ro_op
                  "if available ptp_det then if ptp_routing > """"
                    then ptp_routing else ptp_part
                    else if pt_routing > """" then pt_routing else pt_part"
                  ro_routing ro_routing}

               if recno <> ? then
                  display ro_op @ op_wo_op ro_desc.
               recno = ?.
            end.
            else if frame-field = "prline" then do:

               {mfnp05.i lnd_det lnd_line
                  "lnd_site = input site and lnd_part = input op_part"
                  lnd_line "input prline"}
               if recno <> ? then do:
                  find ln_mstr no-lock where ln_line = lnd_line
                     and ln_site = lnd_site no-error.
                  display lnd_line @ prline.
                  if available ln_mstr then display ln_desc.
               end.
            end.
            else do:
               readkey.
               apply lastkey.
            end.
         end.

         assign prline.

         find pt_mstr no-lock where pt_part = input op_part no-error.
         if not available pt_mstr then do:
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            next-prompt op_part.
            undo, retry.
         end.

         find first ln_mstr no-lock where ln_site = site no-error.
         if available ln_mstr or prline <> "" then do:

            find ln_mstr no-lock where ln_line = prline
               and ln_site = site no-error.
            if not available ln_mstr then do:
               {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
               next-prompt prline.
               display "" @ ln_desc.
               undo,retry.
            end.
            display ln_desc.
         end.
         else
            display "" @ ln_desc.

         /* Added section to locate proper schedule to update */
         assign
            part = input op_part
            op = input op_wo_op.

         {gprun.i ""reoptr1b.p""
            "(site, prline, part, op, last_date,
              output routing, output bom_code, output schedule_id)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if keyfunction(lastkey) = "end-error" then undo, retry.

         if schedule_id = ?
         then do:
            /* Unexploded schedule with consumption period */
            {pxmsg.i &MSGNUM=325 &ERRORLEVEL=3}
            next-prompt op_part.
            undo, retry.
         end.

         /* Locate proper routing and bom code */
         {gprun.i ""reop11a.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if keyfunction(lastkey) = "end-error" then undo, retry.
         if undo-all then undo, retry.

         find wo_mstr no-lock where recid(wo_mstr) = wo_recno.
         find wr_route no-lock where recid(wr_route) = wr_recno.

         if not wr_milestone
         then do:
            {pxmsg.i &MSGNUM=560 &ERRORLEVEL=3} /* OPERATION NOT A MILESTONE */
            undo, retry.
         end.

         if available ro_det
         then
            display ro_desc.
         else
            display wr_desc @ ro_desc.
         find pt_mstr where pt_part = wr_part no-lock no-error.
         if available pt_mstr then display pt_desc1.
         else display " " @ pt_desc1.

         status input.

         /* CREATE OPERATIONS HISTORY RECORDS */
         {gprun.i ""reoptr1i.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

status input.

if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_procs no-error.
if is_wiplottrace_enabled() then
   delete PROCEDURE h_wiplottrace_funcs no-error.
